<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>document对象</title>
		<script type="text/javascript">
			function count() {
				var userName = document.getElementById("userName");
				var hobby = document.getElementsByName("hobby");
				var inputs = document.getElementsByTagName("input");
				var result = "ID为userName的元素的值：" + userName.value + "\nname为hobby的元素的个数：" + hobby.length + "\n个人爱好：";
				for (var i = 0; i < hobby.length; i++) {
					if (hobby[i].checked) {
						result += hobby[i].value + " ";
					}
				}
                result += "\n标签为input的元素的个数：" + inputs.length;
				alert(result);
			}
		</script>
	</head>
	<body>
		<form name="myform">
			用户名：<input type="text" name="userName" id="userName" /><br />
			爱 好：<input type="checkbox" name="hobby" value="音乐" />音乐
			<input type="checkbox" name="hobby" value="美食" />美食
			<input type="checkbox" name="hobby" value="旅游" />旅游<br />
			<input type="button" value="统计结果" onclick="count()" />
		</form>
	</body>
</html>
